﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

public partial class EditHomeEventBaoMing : System.Web.UI.PageEx
{
    private DataSet ds = null;
    public static string strId = "0";
    private int iSelectId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string strResult = string.Empty;
            if (!DalEx.DbUserDalEx.CheckUserLogin(UserType, UserId, ref strResult))
            {
                MessageBox(strResult, "UserLogin.aspx");
                return;
            }
            else
            {
                string strLink = "<li><a href=\"{0}\" class=\"{2}\">{1}</a></li>";
                StringBuilder sbMenuLinks = new StringBuilder();
                if (UserType == 1 && UserId > 0)
                {
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "MemberCenter.aspx", "会员中心", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "UserInfos.aspx", "我的资料", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "ModifyPwd.aspx", "修改密码", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "MyBaoMing.aspx", "我的报名表", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "MyYiGongBaoMing.aspx", "义工报名表", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "MyHomeEventBaoMing.aspx", "家园活动报名表", "on" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "Logout.aspx", "退出系统", "" }));
                }
                else
                {
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "会员中心", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "我的资料", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "修改密码", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "我的报名表", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "义工报名表", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "家园活动报名表", "" }));
                    sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "退出系统", "" }));
                }
                litMenuLinks.Text = sbMenuLinks.ToString();

                DataBinds();
            }
        }
    }
    private void DataBinds()
    {
        int.TryParse(Convert.ToString(Request.QueryString["Id"]), out iSelectId);
        Model.BaoMing3 M_BaoMing = Dal.BaoMing3Dal.Select(iSelectId);
        if (M_BaoMing != null)
        {
            hfSelectId.Value = M_BaoMing.Id.ToString();
            labActivityDate.Text = M_BaoMing.ActivityDate.ToString("yyyy-MM-dd");
            labActivityName.Text = M_BaoMing.ActivityName;
            labActivityOrg.Text = M_BaoMing.ActivityOrg;
            labLimitNums.Text = M_BaoMing.LimitNums.ToString();
            txtBabyClass.Text = M_BaoMing.BabyClass;
            txtBabyName.Text = M_BaoMing.BabyName;
            txtParentName.Text = M_BaoMing.ParentName;
            txtMobile.Text = M_BaoMing.Mobile;
        }

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string strOrderSN = WebBase.Comm.GetOrderNo("ZC");
        string strActivityName = SqlHelper.String(labActivityName.Text);
        string strActivityDate = SqlHelper.String(labActivityDate.Text);
        string strActivityOrg = SqlHelper.String(labActivityOrg.Text);
        int intLimitNums = 0;
        int.TryParse(labLimitNums.Text, out intLimitNums);
        string strBabyClass = SqlHelper.String(txtBabyClass.Text);
        string strBabyName = SqlHelper.String(txtBabyName.Text);
        string strParentName = SqlHelper.String(txtParentName.Text);
        string strMobile = SqlHelper.String(txtMobile.Text);
        if (strBabyClass.Length > 50)
        {
            MessageBox("幼儿班级不能超过50个字！");
            return;
        }
        if (strBabyName.Length > 50)
        {
            MessageBox("幼儿姓名不能超过50个字！");
            return;
        }
        if (strParentName.Length > 100)
        {
            MessageBox("幼儿姓名不能超过100个字！");
            return;
        }
        if (strMobile.Length > 50)
        {
            MessageBox("联系电话不能超过50个字！");
            return;
        }
        int.TryParse(hfSelectId.Value, out iSelectId);
        Model.BaoMing3 M_BaoMing = DalEx.BaoMing3Ex.Select(iSelectId);
        M_BaoMing.ActivityDate = Convert.ToDateTime(strActivityDate);
        M_BaoMing.ActivityID = iSelectId;
        M_BaoMing.ActivityName = strActivityName;
        M_BaoMing.ActivityOrg = strActivityOrg;
        M_BaoMing.LimitNums = intLimitNums;
        M_BaoMing.BabyClass = strBabyClass;
        M_BaoMing.BabyName = strBabyName;
        M_BaoMing.ParentName = strParentName;
        M_BaoMing.Mobile = strMobile;

        int iResult = 0;
        string strResult = string.Empty;
        iResult = DalEx.BaoMing3Ex.Insert(M_BaoMing, ref strResult);
        if (iResult > 0)
        {
           MessageBox(strResult,"MyHomeEventBaoMing.aspx");
        }
        else
        {
            MessageBox(strResult);
        }
    }
}
